<?php
/*+----------------------------------------------+
  |        站点内容审核                          |
  +----------------------------------------------+*/
class WebsiteContentCheckAction extends CommonAction{
    /*+---------------------------------------------+
      |     首页                                    |
      +---------------------------------------------+*/
    public function index(){
           $this->assign("columnName",$this->getColumnSelect());
           if($_POST['show']){
               //根据栏目类型跳转栏目主页面
               if($_POST['column_id']){
                      $column = $this->getColumn($_POST['column_id']);
                      $this->redirect("WebsiteContentCheck/{$column['column_type']}",array("id"=>$column['id']));
               }
           }
           $this->display();
    }

    //获取栏目下拉框
    public function getColumnSelect(){
           //切换数据库
           $this->changeDB();
           $col    = D("website_column");
           $column = $col ->where("column_tablename != '' and column_tablename !='website_article' and status = '1'") ->select();
           return $column;
    }

    //获取站点栏目信息
    public function getColumn($operate){
           $this->changeDB();
           $col    = D("website_column");
           $column = $col ->where("id = {$operate}")->find();
           return $column;
    }
 
    //页面=》新闻中心首页
    public function newsCenter(){
           if($_POST['check']){
               if(count($_POST['id'])){
                         $this->checkContent($_POST);
               }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"newsCenter");
               }
           }
           if($_GET['check']){
               $post['id'][0]     = $_GET['check'];
               $post['column_id'] = $_GET['column_id'];
               $this->checkContent($post);
           }
           if($_POST['look']){
                if(count($_POST['id'])){
                    $in     = $this->arrayToString($_POST['id']);
                    $where  = "id in ({$in})";
                    $this   ->redirect("WebsiteContentCheck/showNews/where/".$where."/column_id/".$_POST['column_id']);
                }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"newsCenter");
                }
           }
           $this->assign("columnName",$this->getColumnSelect());
           //显示该栏目下的新闻
           $this->changeDB();
           $news       = D("website_news");
           if($_GET['search']){
                   $where = "column_id = {$_GET['column_id']} and news_name like '%{$_GET['keyWord']}%'";
                   $_GET['id'] = $_GET['column_id'];
           }else{
                   $where = "column_id = {$_GET['id']}";
           }
           $limit      = $this -> pageOperate("website_news",20,$where);
           $newsColumn = $news -> where($where) ->limit("{$limit['firstRow']},{$limit['listRows']}")->order("id desc") -> select();
           $this->assign("newsColumn",$newsColumn);
           $this->assign("column_id",$_GET['id']);
           $this->display();
    }

    //页面 =》编辑新闻
    public function showNews(){
           $this->assign("columnName",$this->getColumnSelect());
           if($_GET['column_id']){
               $this->assign("column_id",$_GET['column_id']);
           }
           if($_GET['where']){
               $where = $_GET['where'];
           }
           if($_GET['look']){
               $where = "id = {$_GET['look']}";
           }
           $this       ->changeDB();
           $news       = D("website_news"); 
           $newsResult = $news ->where($where)->order("id desc")->select();
           $this       ->assign("newsResult",$newsResult);
           $this->display();
    }

    //是否勾选要管理的项
    public function ifChangeCheckbox($column_id){
               $column = $this->getColumn($column_id);
               $this->assign("jumpUrl",U("WebsiteContentCheck/{$column['column_type']}/id/{$column_id}"));
               $this->error("请勾选要编辑的内容项！");
    }

    //页面=》产品中心首页
    public function productArrondi(){
           if($_POST['check']){
               if(count($_POST['id'])){
                         $this->checkContent($_POST);
               }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"productArrondi");
               }
           }
           if($_GET['check']){
               $post['id'][0]     = $_GET['check'];
               $post['column_id'] = $_GET['column_id'];
               $this->checkContent($post);
           }
           if($_POST['look']){
                if(count($_POST['id'])){
                    $in     = $this->arrayToString($_POST['id']);
                    $where  = "id in ({$in})";
                    $this   ->redirect("WebsiteContentCheck/showProductArrondi/where/".$where."/column_id/".$_POST['column_id']);
                }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"productArrondi");
                }
           }
           $this->changeDB();
           $news       = D("website_product");
           if($_GET['search']){
                   $where = "column_id = {$_GET['column_id']} and product_name like '%{$_GET['keyWord']}%'";
                   $_GET['id'] = $_GET['column_id'];
           }else{
                   $where = "column_id = {$_GET['id']}";
           }
           $limit      = $this -> pageOperate("website_product",20,$where);
           $productColumn = $news -> where($where)-> limit("{$limit['firstRow']},{$limit['listRows']}")->order("id desc") -> select();
           $this->assign("productColumn",$productColumn);
	       $this->assign("columnName",$this->getColumnSelect());
           $this->assign("column_id",$_GET['id']);
           $this->display();
    }
	

    //页面 =》管理产品
    public function showProductArrondi(){
           $this->assign("columnName",$this->getColumnSelect());
           if($_GET['column_id']){
               $this->assign("column_id",$_GET['column_id']);
           }
           if($_GET['where']){
               $where = $_GET['where'];
           }
           if($_GET['look']){
               $where = "id = {$_GET['look']}";
           }

           $this             ->changeDB();
           $product          = D("website_product"); 
           $productResult    = $product ->where($where)->order("id desc")->select();
           $this             ->assign("productResult",$productResult);
           $this->display();
    }
 
    //页面=》产品中心首页
    public function shopAddress(){
           if($_POST['check']){
               if(count($_POST['id'])){
                         $this->checkContent($_POST);
               }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"shopAddress");
               }
           }
           if($_GET['check']){
               $post['id'][0]     = $_GET['check'];
               $post['column_id'] = $_GET['column_id'];
               $this->checkContent($post);
           }
           if($_POST['look']){
                if(count($_POST['id'])){
                    $in     = $this->arrayToString($_POST['id']);
                    $where  = "id in ({$in})";
                    $this   ->redirect("WebsiteContentCheck/showShopAddress/where/".$where."/column_id/".$_POST['column_id']);
                }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"shopAddress");
                }
           }
           $this->changeDB();
           $news           = D("website_address");
           if($_GET['search']){
                   $where = "column_id = {$_GET['column_id']} and shop_name like '%{$_GET['keyWord']}%'";
                   $_GET['id'] = $_GET['column_id'];
           }else{
                   $where = "column_id = {$_GET['id']}";
           }
           $limit      = $this -> pageOperate("website_address",20,$where);
           $addresstColumn = $news -> where($where) ->limit("{$limit['firstRow']},{$limit['listRows']}")->order("id desc") -> select();
           $this->assign("addresstColumn",$addresstColumn);
	       $this->assign("columnName",$this->getColumnSelect());
           $this->assign("column_id",$_GET['id']);
           $this->display();
    }
	
    //页面 =》编辑商店地址
    public function showShopAddress(){
           $this->assign("columnName",$this->getColumnSelect());
           if($_GET['column_id']){
               $this->assign("column_id",$_GET['column_id']);
           }
           if($_GET['where']){
               $where = $_GET['where'];
           }
           if($_GET['look']){
               $where = "id = {$_GET['look']}";
           }
           $this          ->changeDB();
           $news          = D("website_address"); 
           $addressResult = $news ->where($where)->order("id desc")->select();
           $this          ->assign("addressResult",$addressResult);
           $this          ->display();
    }
	
	//页面 =》人才招聘首页
    public function personnelRecruitment(){
           if($_POST['check']){
               if(count($_POST['id'])){
                         $this->checkContent($_POST);
               }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"personnelRecruitment");
               }
           }
           if($_GET['check']){
               $post['id'][0]     = $_GET['check'];
               $post['column_id'] = $_GET['column_id'];
               $this->checkContent($post);
           }
           if($_POST['look']){
                if(count($_POST['id'])){
                    $in     = $this->arrayToString($_POST['id']);
                    $where  = "id in ({$in})";
                    $this   ->redirect("WebsiteContentCheck/showPersonnelRecruitment/where/".$where."/column_id/".$_POST['column_id']);
                }else{
                    $this->ifChangeCheckbox($_POST['column_id'],"personnelRecruitment");
                }
           }
           $this->assign("columnName",$this->getColumnSelect());
           //显示该栏目下的新闻
           $this->changeDB();
           $news       = D("website_news");
           if($_GET['search']){
                   $where = "column_id = {$_GET['column_id']} and news_name like '%{$_GET['keyWord']}%'";
                   $_GET['id'] = $_GET['column_id'];
           }else{
                   $where = "column_id = {$_GET['id']}";
           }
           $limit      = $this -> pageOperate("website_news",20,$where);
           $newsColumn = $news -> where($where) ->limit("{$limit['firstRow']},{$limit['listRows']}")->order("id desc") -> select();
           $this->assign("newsColumn",$newsColumn);
           $this->assign("column_id",$_GET['id']);
           $this->display();
    }

    //页面 =》编辑人才招聘
    public function showPersonnelRecruitment(){
           $this->assign("columnName",$this->getColumnSelect());
           if($_GET['column_id']){
               $this->assign("column_id",$_GET['column_id']);
           }
           if($_GET['where']){
               $where = $_GET['where'];
           }
           if($_GET['look']){
               $where = "id = {$_GET['look']}";
           }
           $this       ->changeDB();
           $news       = D("website_news"); 
           $newsResult = $news ->where($where)->order("id desc")->select();
           $this       ->assign("newsResult",$newsResult);
           $this->display();
    }

    //审核
    public function checkContent($post){
           $this->changeDB();
           //状态反转
           $columnInfo = $this->getColumn($post['column_id']);
           $check      = D($columnInfo['column_tablename']);
           foreach($post['id'] as $key => $val){
               $status  = $check ->field("id,status")->where("id = {$val}")->find();
               //var_dump($status);
               if($status['status'] == 0){
                     $status['status'] = "1";

               }elseif($status['status'] == 1){
                     $status['status'] = "0";
               }
               $sta += $check ->save($status);
           }
           if($sta){
                  $this->success("成功的审核了 {$sta} 项！");
           }else{
                  $this->error("审核失败！");
           }
           
    }

}
?>
